home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo1.zoo / demo / icon / overlay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-24  |  2.7 KB  |  113 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: overlay.c,v 1.1 88/07/08 11:56:58 sau Exp $
  9.     $Source: /tmp/mgrsrc/demo/icon/RCS/overlay.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/icon/RCS/overlay.c,v $$Revision: 1.1 $";
  12.  
  13. /*    overlay        (S A Uhler)
  14.  *
  15.  *    enable/disable color overlay plane  (wrong version)
  16.  */
  17.  
  18. #include <sys/types.h>
  19. #include <sys/ioctl.h>
  20. #include <sun/fbio.h>
  21. #include <sys/file.h>
  22. #include <sys/mman.h>
  23. #include <stdio.h>
  24.  
  25. #define SCREEN    "/dev/cgfour0"    /* name of sun frame buffer */
  26.  
  27. main(argc,argv)
  28. int argc;
  29. char **argv;
  30.    {
  31.    int how;
  32.  
  33.    if (argc < 2) {
  34.       fprintf(stderr,"usage: %s [on|off]\n",*argv);
  35.       exit(3);
  36.       }
  37.  
  38.    if (strcmp(argv[1],"on") == 0)
  39.       how = -1;
  40.    else
  41.       how = 0;
  42.  
  43.    overlay(how);
  44.    }
  45.  
  46. overlay(how)
  47. register int how;
  48.    {
  49.    int fd;
  50.    char  *malloc();
  51.    register int *start,*end;
  52.    int *addr;
  53.    struct fbtype buff;
  54.    int size,temp,pagesize;
  55.    int bits;
  56.  
  57.    /* open the SUN screen */
  58.  
  59.    if ((fd = open(SCREEN,O_RDWR)) <0) {
  60.       fprintf(stderr,"Can't open %s\n",SCREEN);
  61.       exit(1);
  62.       }
  63.  
  64.    /* get the frame buffer size */
  65.  
  66.    if (ioctl(fd,FBIOGTYPE,&buff) < 0) {
  67.       fprintf(stderr,"Can't get %s parameters\n",SCREEN);
  68.       exit(2);
  69.       }
  70.    /* sun returns the wrong value ...
  71.    if (buff.fb_type != FBTYPE_SUN4COLOR) {
  72.       fprintf(stderr,"Wrong frame buffer type (%d)\n",buff.fb_type);
  73.       exit(4);
  74.       }
  75.    */
  76.    /* malloc space for frame buffer  -- overlay and enable planes */
  77.  
  78.    pagesize = getpagesize();
  79.    bits = buff.fb_width * buff.fb_height;            /* pixels/plane */
  80.    size = bits >> 2;    /* bitplane size in bytes  * 2 */
  81.    size = (size+pagesize-1) &~ (pagesize-1);        /* round up to next page */
  82.  
  83.    if ((temp = (int) malloc(size+pagesize)) == 0) {
  84.       fprintf(stderr,"couldn't malloc %d bytes\n",size+pagesize);
  85.       exit(3);
  86.       }
  87.  
  88.    /* align space on a page boundary */
  89.  
  90.    addr = (int *)(((unsigned int)temp+pagesize-1) & ~(pagesize-1));
  91.  
  92.    /* map the frame buffer into malloc'd space */
  93.  
  94.    if (mmap(addr,size,PROT_WRITE,MAP_SHARED,fd,0) < 0) {
  95.       perror("mmap");
  96.       exit(5);
  97.       }
  98.   
  99.    /* write data to plane */
  100.  
  101.    start = addr + (1024*128/4); /* start of enable  plane */
  102.    end =   start +(bits>>5);    /* end of enable plane */
  103.  
  104.    while(start < end) {
  105.       *start++ = how;
  106.       }
  107.  
  108.    /* clean up and exit */
  109.  
  110.    munmap(addr,buff.fb_size);
  111.    exit(0);
  112.    }
  113.